import { Next } from 'koa';
import CryptoJS from 'crypto-js';
import { KoaContext } from '@/types/koa';

// ? md5加密
type MD5 = {
  key: 'password';
}
export const md5 = ({
  key,
}: MD5) => async (ctx: KoaContext, next: Next) => {
  ctx.request.body[key] = CryptoJS.MD5(ctx.request.body[key] as string).toString().toLocaleUpperCase();

  await next();
};
